import { PUSH, UPDATE } from './constants'
const initState = {
  list: [
    { name: 'hj', info: 'lsp1' },
    { name: 'lt', info: 'lsp0' },
    { name: 'lw', info: 'xiaosan' },
  ],
}

export default function reducer(state = initState, action) {
  switch (action.type) {
    case PUSH:
      const newList = [...state.list]
      newList.push(action.payload)
      return {
        ...state,
        list: newList,
      }
    case UPDATE:
      const nList = state.list.map((item) => {
        if (item.name === 'lt') item.info = '嗨丝陶'
        return item
      })
      return {
        ...state,
        list: nList,
      }
    default:
      return state
  }
}
